package metis.lab.hygeia.pojos;

import com.google.appengine.api.datastore.Key;
import java.util.Date;
import java.util.Calendar;

import javax.jdo.PersistenceManager;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import metis.lab.hygeia.jdo.PMF;

@PersistenceCapable
public class Account {
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
	
	@Persistent
    private String name;
	
	@Persistent
    private String email;
	
	@Persistent
    private String password;
	
	@Persistent
    private String gender;
	
	@Persistent
    private String zipcode;
	
	@Persistent
    private String country;
	
	@Persistent
    private Date date_created;
	
	@Persistent
    private Date date_modified;
	
	/*
	 * record status: 1=active, 0=suspended, -1=cancelled
	 */
	@Persistent
    private int status=1;
	
	/*
	 * record type: free, premium
	 */
	@Persistent
    private String type="free";
	
	@Persistent
    private int limit_a=0;
	
	@Persistent
    private int limit_b=1;

	
		
	
	public Account(String name, String email, String password, String gender,
			String zipcode, String country, Date date_created,
			Date date_modified, int status, String type, int limit_a,
			int limit_b) {
		super();
		this.name = name;
		this.email = email;
		this.password = password;
		this.gender = gender;
		this.zipcode = zipcode;
		this.country = country;
		this.date_created = date_created;
		this.date_modified = date_modified;
		this.status = status;
		this.type = type;
		this.limit_a = limit_a;
		this.limit_b = limit_b;
	}

	public Account(String name, String email, String password) {
		super();
		this.name = name;
		this.email = email;
		this.password = password;
		this.gender = "";
		this.zipcode = "";
		this.country = "";
		this.date_created = Calendar.getInstance().getTime();
		this.date_modified = Calendar.getInstance().getTime();
		this.status = 1;
		this.type = "free";
		this.limit_a = 0;
		this.limit_b = 0;
	}
	/**
	 * @return the key
	 */
	public Key getKey() {
		return key;
	}

	/**
	 * @param key the key to set
	 */
	public void setKey(Key key) {
		this.key = key;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return the gender
	 */
	public String getGender() {
		return gender;
	}

	/**
	 * @param gender the gender to set
	 */
	public void setGender(String gender) {
		this.gender = gender;
	}

	/**
	 * @return the zipcode
	 */
	public String getZipcode() {
		return zipcode;
	}

	/**
	 * @param zipcode the zipcode to set
	 */
	public void setZipcode(String zipcode) {
		this.zipcode = zipcode;
	}

	/**
	 * @return the country
	 */
	public String getCountry() {
		return country;
	}

	/**
	 * @param country the country to set
	 */
	public void setCountry(String country) {
		this.country = country;
	}

	/**
	 * @return the date_created
	 */
	public Date getDate_created() {
		return date_created;
	}

	/**
	 * @param date_created the date_created to set
	 */
	public void setDate_created(Date date_created) {
		this.date_created = date_created;
	}

	/**
	 * @return the date_modified
	 */
	public Date getDate_modified() {
		return date_modified;
	}

	/**
	 * @param date_modified the date_modified to set
	 */
	public void setDate_modified(Date date_modified) {
		this.date_modified = date_modified;
	}

	/**
	 * @return the status
	 */
	public int getStatus() {
		return status;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(int status) {
		this.status = status;
	}

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @return the limit_a
	 */
	public int getLimit_a() {
		return limit_a;
	}

	/**
	 * @param limit_a the limit_a to set
	 */
	public void setLimit_a(int limit_a) {
		this.limit_a = limit_a;
	}

	/**
	 * @return the limit_b
	 */
	public int getLimit_b() {
		return limit_b;
	}

	/**
	 * @param limit_b the limit_b to set
	 */
	public void setLimit_b(int limit_b) {
		this.limit_b = limit_b;
	}
	
	
	public void store(){
		PersistenceManager pm = PMF.get().getPersistenceManager();
	    try {
	        pm.makePersistent(this);
	    } finally {
	        pm.close();
	    }
		
	}
}
